<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <style type="text/css">
        .header {
            padding: 2.5rem 0.5rem 2rem 0.5rem;
        }
    </style>
</head>

<body>

    <style>
        html,
        body {
            height: 100%;
        }
    </style>
    <div class="login-bg">
        <img class="logo" src="./image/login-logo.jpg">
        <div class="login">
            <ul>
                <li>
                    <label><i class="aui-iconfont aui-icon-my"></i></label>
                    <input type="text" placeholder="" id="user_name">
                </li>
                <li>
                    <label><i class="aui-iconfont aui-icon-lock"></i></label>
                    <input type="password" placeholder="" id="user_pwd">
                </li>
            </ul>
        </div>
        <div class="aui-content-padded">
            <div class="aui-btn aui-btn-success aui-btn-block aui-btn-sm" onclick="login();">登录</div>
        </div>
        <p>可大金融智能办公系统</p>
    </div>



</body>

<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    function openClub() {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: 'club_win',
            url: './html/club_win.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    }

    function closeWin() {
        api.closeWin({});
    }

    apiready = function() {

        // get_registration();
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                api.closeWidget({
                    id: 'A6005644866201',
                    retData: {
                        name: 'closeWidget'
                    },
                    animation: {
                        type: 'flip',
                        subType: 'from_bottom',
                        duration: 500
                    }
                });
            } else {
                // alert(JSON.stringify(err));
            }
        });

        // if ($api.getStorage('id')) {
        //     api.openWin({
        //         name: 'home',
        //         url: './home.html',
        //         slidBackEnabled: false,
        //         pageParam: {
        //             name: 'test'
        //         }
        //     });
        // }
        addJKPush();


    }

    function addJKPush() {
        var ajpush = api.require('ajpush');

        api.addEventListener({
            name: 'appintent'
        }, function(ret, err) {
            var ret = ret;
            var pageSign = ret.appParam.ajpush.extra.pageSign;
            // alert(pageSign);
        })

        if (api.systemType == "android") {
            ajpush.init(function(ret) {
                var param = {
                    alias: 'user1',
                    tags: ['user']
                };
                ajpush.bindAliasAndTags(param, function(ret) {

                });
            });
        }
    }

    function login() {
        var user_name = $("#user_name").val();
        var user_pwd = $("#user_pwd").val();

        api.ajax({
            url: 'http://oa.big-wealth.com/index.php?m=&c=public&a=check_login_api',
            method: 'post',
            data: {
                values: {
                    emp_no: user_name,
                    password: user_pwd
                },
            }
        }, function(ret, err) {
            if (ret) {
                // console.log(JSON.stringify(ret));
                if (ret.status == 200) {
                    api.toast({
                        msg: '登陆成功！',
                        duration: 1500,
                        location: 'bottom',
                        global: true
                    });
                    $api.setStorage('id', ret.date.id);
                    $api.setStorage('name', ret.date.name);
                    $api.setStorage('letter', ret.date.letter);
                    $api.setStorage('position_name', ret.date.position_name); // 职位
                    $api.setStorage('dept_name', ret.date.dept_name); // 部门
                    $api.setStorage('user_data', ret); // 部门

                    api.execScript({
                        name: 'root',
                        script: 'gotoUser();'
                    });

                    api.closeWin();

                    var push = 'jg_push("' + ret.date.alias + '","' + ret.date.tags + '")';
                    api.execScript({
                        script: push
                    });


                } else {
                    alert(ret.error);
                }
            } else {
                // alert(JSON.stringify(err));
                alert('帐号或密码错误！');
            }
        });

    }






    function jg_push(alias, tags) {

        var ajpush = api.require('ajpush');
        var param = {
            alias: alias,
            tags: [tags]
        };
        ajpush.bindAliasAndTags(param, function(ret) {
            var statusCode = ret.statusCode;
            if (statusCode == '0') {
                ajpush.getRegistrationId(function(ret) {
                    var registrationId = ret.id;
                    console.log(registrationId);
                    post_registration(registrationId)
                        // $api.setStorage('registrationId', registrationId);
                });
            }
        });
    }

    // 140fe1da9eed3b57536 乔磊
    // 160a3797c8585ec46b8 韩
    //1114a89792f4ebafbd1
    function post_registration(registrationId) {
        var id = $api.getStorage('id');

        api.ajax({
            url: 'http://oa.big-wealth.com/index.php?m=&c=user&a=registration&api_auth_id=3',
            method: 'post',
            data: {
                values: {
                    registrationid: registrationId,
                    userid: id
                },

            }
        }, function(ret, err) {
            if (ret) {
                // alert( JSON.stringify( ret ) );
            } else {
                alert(JSON.stringify(err));
            }
        });





    }
</script>

</html>
